package homework;

/**
 * 5.随机生成10个整数(1_100的范围)保存到数组，并倒序打印以及求平均值、求最大
 * 值和最大值的下标、并查找里面是否有8 Homework05.java
 */
public class demo01 {
    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            //1-100
            arr[i] = (int) (Math.random() * 100) + 1;
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        int max = 0;
        int maxIndex = 0;
        boolean haveEight = false;
        double sum = 0;
        System.out.println("倒序打印");
        for (int i = arr.length - 1; i >= 0; i--) {
            if(max<arr[i]){
                max = arr[i];
                maxIndex = i;
            }
            if(arr[i] == 8){
                haveEight = true;
            }
            System.out.print(arr[i] + " ");
            sum += arr[i];
        }
        //求平均值
        System.out.println();
        System.out.println("平均值为：" + sum / arr.length);
        System.out.println("最大值：" + max);
        System.out.println("最大值下标：" + maxIndex);
        System.out.println("是否有8：" + haveEight);

    }
}
